package com.ccdt.tv.roundprogram.view.custom;

import android.view.KeyEvent;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;


/**
 * 简化OnKeyListener的逻辑，处理前、后、左、右、中、回退等按键，返回值代表是否拦截
 */
public class MyOnKeyAdapter implements View.OnKeyListener {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        LogUtils.i("MyOnKeyAdapter", "onKeyDown " + keyCode+" "+v.toString());
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_RIGHT:
                    return onRight(v);
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    return onLeft(v);
                case KeyEvent.KEYCODE_DPAD_UP:
                    return onUp(v);
                case KeyEvent.KEYCODE_DPAD_DOWN:
                    return onDown(v);
                case KeyEvent.KEYCODE_DPAD_CENTER:
                    return onCenter(v);
                case KeyEvent.KEYCODE_MENU:
                    return onMenu(v);
                case KeyEvent.KEYCODE_BACK:
                    return onBack(v);
            }
        }
        return false;
    }

    protected boolean onBack(View v) {
        return false;
    }

    protected boolean onMenu(View v) {
        return false;
    }

    protected boolean onRight(View v) {
        return false;
    }

    protected boolean onLeft(View v) {
        return false;
    }

    protected boolean onUp(View v) {
        return false;
    }

    protected boolean onDown(View v) {
        return false;
    }

    protected boolean onCenter(View v) {
        return false;
    }
}


